Skip to content

fix(hygon/platform): Improve Hygon library path resolution, fall back…#82

Merged
zhaoyinglia merged 2 commits into
flagos-ai:mainfrom
wangxshuai:main
Jun 29, 2026
Merged

fix(hygon/platform): Improve Hygon library path resolution, fall back…#82
zhaoyinglia merged 2 commits into
flagos-ai:mainfrom
wangxshuai:main

Conversation

@wangxshuai

Copy link
Copy Markdown

Description

When loading Hygon libraries, the code previously assumed that
hygon_spec.origin is always available and directly accessed it to
determine the package path.

However, for namespace packages or certain installation layouts,
importlib.util.find_spec() may return a spec whose origin is None,
causing an exception when accessing Path(hygon_spec.origin).

This PR adds a fallback mechanism:

  • Use hygon_spec.origin when available.
  • Fall back to hygon_spec.submodule_search_locations when origin is
    None.
  • Return gracefully with an error message if neither source can provide
    a valid package path.

This improves compatibility with different Python package layouts and
prevents startup failures when loading Hygon-related libraries.

Fixes # (issue)

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Add a null check for hygon_spec.origin
  • Fall back to hygon_spec.submodule_search_locations[0] when origin is unavailable
  • Add explicit error handling when neither origin nor submodule_search_locations can determine the package path
  • Prevent crashes caused by Path(None) during Hygon library loading

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

… to submodule search locations when origin is None
@CLAassistant

CLAassistant commented Jun 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@zhaoyinglia zhaoyinglia merged commit 5dd31d7 into flagos-ai:main Jun 29, 2026
14 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants